package cn.kgm.flyweight;

import cn.kgm.flyweight.shape.Circle;
import cn.kgm.flyweight.shape.Shape;

import java.util.HashMap;

public class ShapeFactory {
    // final 修饰只是引用不能变，里面的值是可以变的
    // 比如不能给circlemap 赋值为 new hashMap
    private static final HashMap<String, Shape> circleMap = new HashMap<>();

    public static Shape getCircle(String color) {
        Circle circle = (Circle) circleMap.get(color);

        if (circle == null) {
            circle = new Circle(color);
            circleMap.put(color, circle);
            System.out.println("Creating circle of color : " + color);
        }
        return circle;
    }
}
